package com.controller;

import com.entity.Student;
import com.service.StudentService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping(value = "/Student")
public class StudentController {

    @Resource
    private StudentService service;
    @RequestMapping(value = "/add",method = RequestMethod.POST)
    public ModelAndView addStudent(Student student){
        ModelAndView mv = new ModelAndView();
       int i= service.addStudent(student);
        if (i != 0){
            System.out.println("数据插入成功");
            mv.addObject("tips","插入学生"+student.getName()+"成功");
            mv.setViewName("showstudent");
        }
        return mv;
    }
    @RequestMapping(value = "/query")
    @ResponseBody
    public List<Student> queryStudent(){
        List<Student> students = service.queryallStudent();
        return students;
    }


}


